package com.ruoyi.web.controller.bl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bl.service.IBlCompanyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bl.domain.BlCompany;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下游公司Controller
 * 
 * @author ruoyi
 * @date 2023-08-21
 */
@RestController
@RequestMapping("/bl/company")
public class BlCompanyController extends BaseController
{
    @Autowired
    private IBlCompanyService blCompanyService;

    /**
     * 查询下游公司列表
     */
    @PreAuthorize("@ss.hasPermi('bl:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlCompany blCompany)
    {
        startPage();
        List<BlCompany> list = blCompanyService.selectBlCompanyList(blCompany);
        return getDataTable(list);
    }

    /**
     * 导出下游公司列表
     */
    @PreAuthorize("@ss.hasPermi('bl:company:export')")
    @Log(title = "下游公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlCompany blCompany)
    {
        List<BlCompany> list = blCompanyService.selectBlCompanyList(blCompany);
        ExcelUtil<BlCompany> util = new ExcelUtil<BlCompany>(BlCompany.class);
        util.exportExcel(response, list, "下游公司数据");
    }

    /**
     * 获取下游公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('bl:company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(blCompanyService.selectBlCompanyByCompanyId(companyId));
    }

    /**
     * 新增下游公司
     */
    @PreAuthorize("@ss.hasPermi('bl:company:add')")
    @Log(title = "下游公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlCompany blCompany)
    {
        blCompany.setCreateBy(getUsername());
        return toAjax(blCompanyService.insertBlCompany(blCompany));
    }

    /**
     * 修改下游公司
     */
    @PreAuthorize("@ss.hasPermi('bl:company:edit')")
    @Log(title = "下游公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlCompany blCompany)
    {
        blCompany.setUpdateBy(getUsername());
        return toAjax(blCompanyService.updateBlCompany(blCompany));
    }

    /**
     * 删除下游公司
     */
    @PreAuthorize("@ss.hasPermi('bl:company:remove')")
    @Log(title = "下游公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(blCompanyService.deleteBlCompanyByCompanyIds(companyIds));
    }
}
